package com.yuerlive.rainbow.module.mine.presenter;

import com.yuerlive.rainbow.api.UserApi;
import com.yuerlive.rainbow.api.UserService;
import com.yuerlive.rainbow.base.BasePresenterImpl;
import com.yuerlive.rainbow.entity.BaseData;
import com.yuerlive.rainbow.entity.User;
import com.yuerlive.rainbow.rx.RxHelper;
import com.yuerlive.rainbow.rx.RxObserver;
import com.yuerlive.rainbow.utils.UserProxy;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by xiaoyi on 2017/5/31.
 */

public class FeedbackPresenter extends BasePresenterImpl implements FeedbackContract.Presenter {
    private FeedbackContract.View view;
    private UserService userService;

    public FeedbackPresenter(FeedbackContract.View view) {
        this.view = view;
        this.view.setPresenter(this);
        this.userService = UserApi.getInstance().service;
    }

    @Override
    public void commitFeedback(String content) {
        view.showLoading();
        Map<String, String> params = new HashMap<>();
        User user = UserProxy.getUser();
        params.put("content", content);
        userService.commitFeedback(params).compose(RxHelper.toUI())
                .subscribe(new RxObserver<BaseData>(this) {
                    @Override
                    protected void onSuccess(BaseData baseData) {
                        view.hideLoading();
                        view.showResult(baseData.getCode());
                    }

                    @Override
                    protected void onFail(String message) {

                    }
                });
    }
}
